#include <WiFi.h>

const char *DeviceName = "ESP32C3";
const char *ssid = "leisure";
const char *password = "shadow27";

IPAddress staticIP(192, 168, 212, 153); // 开发板的静态IP
IPAddress gateway(192, 168, 212, 82);   // 网关，路由器的IP地址
IPAddress subnet(255, 255, 255, 0);     // 子网掩码

extern void Websocket(void *pt);
void ConnectWifi();

void setup()
{
  Serial.begin(115200);
  ConnectWifi();

  xTaskCreate(Websocket, "", 1024 * 5, NULL, 2, NULL);
}

void loop()
{
}

void ConnectWifi()
{
  WiFi.hostname(DeviceName);
  WiFi.config(staticIP, gateway, subnet);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    vTaskDelay(500);
    Serial.print(F("."));
  }

  Serial.println(F(""));
  Serial.println(F("WiFi Connected!"));
  Serial.print("IP:");
  Serial.println(WiFi.localIP());
}